; ***************************************************************************
;   Group: Fantastic Five
;   Date: 4/24/08
;   Description: Program to compute and print part of the Fibonacci sequence
; ***************************************************************************
;
BEG             ; Begin program
;
;
GET     R7      ; Get user's input
SUB     R7,2    ; Subtract 2 from user's input to account for first two digits being 1
PTC     '\n'    ; Print new line
;
CPY     R7,R5   ; Copy R7 into another register
INC     R5      ; Add 1 to Register 5 (this is so that we can check if user entered 1)
JLT     R5,38   ; Check for invalid input
;
MOV     R0,1    ; Initialize first two sequence values to 1
MOV     R1,1    ; Continued
PUT     R0      ; Print first value and a space
PTC     '\s'    ;
MOV     R6,-1   ; Put 1 into R6
CMP     R7,R6   ; See if user entered 1
JZ      RC,46   ; Jump to end if user entered 1
PUT     R1      ; Print second value and a space
PTC     '\s'    ;
JZ      R7,46   ; If user only entered 2, we're done
;
CPY     R0,R2   ; Copy first value into temporary register
ADD     R0,R1   ; Add registers
CPY     R2,R1   ; Copy temporary value over second value
PUT     R0      ; Output result and space
PTC     '\s'    ;
DEC     R7      ; Decrement counter
JGT     R7,29   ; Jump back to beginning of loop if counter non-zero
JMP     46      ; Jump to end, done
;
PTC     'I'     ; Print error message for 0 or negative input
PTC     'N'     ;
PTC     'V'     ;
PTC     'A'     ;
PTC     'L'     ;
PTC     'I'     ;
PTC     'D'     ; End of error message
;
PTC     '\n'    ; Print a new line
END             ; End of program
